package com.yiwei.hdb.api.requestInfo;

import com.yiwei.hdb.api.Api;
import com.yiwei.hdb.api.bean.AlipayListBean;
import com.yiwei.hdb.api.bean.AlipayOperator;
import com.yiwei.hdb.api.bean.LoginBean;
import com.yiwei.hdb.api.callback.AlipayOperatorContract;
import com.yiwei.hdb.api.callback.LoginContract;
import com.yiwei.hdb.util.Network;
import com.yiwei.hdb.util.RxLifeUtil;
import com.yiwei.hdb.util.ToastUtil;

/**
 * Created by Administrator on 2017/5/14.
 */

public class AlipayRequest extends BaseRequest<AlipayOperatorContract.View> implements AlipayOperatorContract.Presenter<AlipayOperatorContract.View> {

    public static AlipayRequest create() {
        return new AlipayRequest();
    }

    //    create、 update、 delete
    public String CREATE = "create";
    public String UPDATE = "update";
    public String DELETE = "delete";

    @Override
    public void getAlipayList() {
        if (!Network.checkNetwork(BaseContext)) {
            ToastUtil.makeText(BaseContext, networkFail);
            return;
        }
        mView.onRequestStart();
        AlipayListBean bean = new AlipayListBean();
        bean.payment_id = "3";
        Api.api_service.getAlipayList(bean).compose(RxLifeUtil.checkOn(BaseContext)).
                doFinally(() -> {
                    try {
                        mView.complete();
                    } catch (NullPointerException e) {

                    }
                }).
                subscribe(result -> {
                    mView.getAlipayListSuccess(result);
                });
    }

    @Override
    public void operatorUser(String action, String account) {
        if (!Network.checkNetwork(BaseContext)) {
            ToastUtil.makeText(BaseContext, networkFail);
            return;
        }
        mView.onRequestStart();
        AlipayOperator bean = new AlipayOperator();
        bean.account = account;
        bean.action = action;
        bean.payment_id = "3";
        Api.api_service.operatorAlipay(bean).compose(RxLifeUtil.checkOn(BaseContext)).
                doFinally(() -> {
                    try {
                        mView.complete();
                    } catch (NullPointerException e) {

                    }
                }).
                subscribe(result -> {
                    mView.operatorUserSuccess();
                });
    }
}
